<template>
  <div>
    <el-dialog :destroy-on-close="true" :lock-scroll="false" title="拒绝" :visible.sync="visible" width="750px" :before-close="cancel">
      <el-form label-width="100px" style="margin-top: 20px" :rules="rules" :model="form" ref="form">
        <el-form-item label="拒绝理由" prop="description">
          <el-input v-model="form.description" placeholder="请输入理由" type="textarea" :rows="4"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button   @click="cancel">取消</el-button>
        <el-button @click="submitReject('form')" type="primary" :loading="loading">提交</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: {
    // 修改回显的数据
    data: Object,
    type:String
  },
  data() {
    return {
      id:null,
      loading: false,
      /*拒绝表单验证*/
      rules: {
        description: [
          {required: true, message: '请输入拒绝理由', trigger: 'blur'},
        ],
      },
      form:{},
      /*拒绝弹窗*/
      visible:false,

    }
  },
  methods: {
    active( id) {
      this.visible = true;
      this.id=id
    },
    /*提交拒绝*/
    submitReject(formName){
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.loading=true
          this.$http.post(`/inventories_audit/${this.id}/reject`,this.form).then((res) => {
            if(res.data.code===0){
              this.$message.success(res.data.msg)
              this.cancel()
              if(this.type==='sce'){
                this.$emit('done')
              }else {
                this.$emit('reload')
              }
            }else {
              this.cancel()
              this.$message.error(res.data.msg)
            }

          })
          /*发起请求*/
        } else {
          return false;
        }
      });
    },
    reject() {
      this.visible=true
    },
    cancel(){
      this.visible = false
      this.loading=false
      Object.assign(this.$data, this.$options.data())
    },
  }
}
</script>

<style lang="scss" scoped>

</style>
